package com.travelsmart.client.apresentacao.widget;

import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.VerticalPanel;

public class FormRadioButton extends FormWidget<String>{
	
	private RadioButton[] radios;
	
	public FormRadioButton(String infoHelp, String radioButtonName, boolean vertical, final String[] valores, final HandlerValidation<String> handler){
		super(handler);
		radios =  new RadioButton[valores.length];
		Panel lpanel = null;
		if(vertical){
			lpanel = new VerticalPanel();
		}else{
			lpanel = new HorizontalPanel();
		}
		for (int i = 0; i < valores.length; i++) {
			radios[i] = new RadioButton("bandeira", valores[i]);
			lpanel.add(radios[i]);
		}
		super.panel.add(lpanel);
		initHelp(infoHelp);
		initWidget(super.panel);
		
	}

	@Override
	public String getValue() {
		String retorno = "";
		if(radios != null){
			for (int i = 0; i < radios.length; i++) {
				if(radios[i].getValue()){
					retorno = radios[i].getText();
				}
			}
		}
		return retorno;
	}
	@Override
	public void setFocus(boolean focused) {
		radios[0].setFocus(focused);
		
	}
	
}
